﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Project
{
    public partial class YGxiu : Form
    {
        public int id;
        public YGxiu()
        {
            InitializeComponent();
        }

        private void YGxiu_Load(object sender, EventArgs e)
        {
            string sql = "select * from Branch";
            DataTable dt = FrmHotel.DBHelper.SelectForTable(sql);
            this.comboBox2.DisplayMember = "BranchName";
            this.comboBox2.ValueMember = "BranchId";
            this.comboBox2.DataSource = dt;


            string sql1 = "select * from EyState";
            DataTable dt1 = FrmHotel.DBHelper.SelectForTable(sql1);
            this.comboBox3.DisplayMember = "ESName";
            this.comboBox3.ValueMember = "ESId";
            this.comboBox3.DataSource = dt1;
            s();
        }
        public void s() 
        {
           
            string sql = "select * from EyInfo where EyId= "+id;
            SqlDataReader reader = FrmHotel.DBHelper.SelectMore(sql);
            int gang = 0;
            int zt = 0;
            if(reader.Read())
            {
                this.textBox2.Text = reader["EyName"].ToString();
                this.textBox1.Text = reader["EySex"].ToString();
                this.dateTimePicker1.Text = reader["EyBay"].ToString();
                gang = Convert.ToInt32(reader["EyBranchId"]);
                this.dateTimePicker2.Text = reader["EyTime"].ToString();
                this.textBox4.Text = reader["EyPhone"].ToString();
                this.textBox3.Text = reader["EyAddress"].ToString();
               zt= Convert.ToInt32(reader["EyState"]);

            }
            reader.Close();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
           
        }

        private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string name = this.textBox2.Text;
            string sex = this.textBox1.Text;
            string birthday = this.dateTimePicker1.Value.ToString();
            int gId =Convert.ToInt32(this.comboBox2.SelectedValue);
            string date = this.dateTimePicker2.Value.ToString();
            string phone = this.textBox4.Text;
            string address = this.textBox3.Text;
            int zId = Convert.ToInt32(this.comboBox3.SelectedValue);
            if(string.IsNullOrEmpty(name)||string.IsNullOrEmpty(phone)||string.IsNullOrEmpty(address))
            {
                MessageBox.Show("请填写完整");
            }
            string sql = string.Format("update EyInfo  set EyName='{0}',EySex='{1}',EyBay='{2}',EyBranchId={3},EyTime='{4}',EyPhone='{5}',EyAddress='{6}',EyState={7} where EyId={8}", name, sex, birthday, gId, date, phone, address, zId,id);
            int result = FrmHotel.DBHelper.ExecuteUpdate(sql);
            if (result > 0)
            {
                MessageBox.Show("修改成功");
                this.Close();
            }
            else 
            {
                MessageBox.Show("只有离职的人员方可删除信息");
            }
                                                                                                                                                                                                      
        }
    }
}
